home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gawk
/
cawf2st.zoo
/
fontfilt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-12
|
25KB
|
811 lines
/*
* fontfilt.c - cawf post-processing font filter
*
* V. Abell
* Purdue University Computing Center
*
* Fontfilt filters output from cawf, the C version of Henry Spencer's
* Amazingly Workable (text) Formatter, awf, to produce printer-specific
* codes for bold and italic characters. (Cawf provides modest support
* for documents formatted with nroff's man(7) and ms(7) macros.)
*
* Fontfilt is based on work by and suggestions from Chet Creider
* <creider@csd.uwo.ca>.
*/
/*
* Copyright (c) 1991 Purdue University Research Foundation,
* West Lafayette, Indiana 47907. All rights reserved.
*
* Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue
* University Computing Center. Not derived from licensed software;
* derived from work by Chet Creider <creider@csd.uwo.ca>.
*
* Permission is granted to anyone to use this software for any
* purpose on any computer system, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The author is not responsible for any consequences of use of
* this software, even if they arise from flaws in it.
*
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission. Credits must appear in the
* documentation.
*
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software. Credits must
* appear in the documentation.
*
* 4. This notice may not be removed or altered.
*/
/*
* Usage:
*
* fontfilt [-c config] [-d device] [-f font] [file(s)]
*
* where:
*
* -c config specifies an alternate configuration file
* (default directory = CAWFLIB definition or
* CAWFLIB env. variable)
*
* -d device specifies the output device
*
* -f font specifies the font to be used on the
* output device
*
* file(s) the path(s) to the file(s) containing cawf,
* -fe format output
*
* Cawf's font ESCape mode must be used - e. g.,
*
* % cawf -fe -man cawf.1 | fontfilt -dlj3 -flg12
*/
/*
* See fontfilt.cf for a list of supported devices and fonts, or use
* the -h (help) option. The default device is the last device named
* in fontfilt.cf.
*/
#include <stdio.h>
#ifdef STDLIB
#include <stdlib.h>
#endif
#ifdef UNIX
#ifdef USG
#include <string.h>
#else
#include <strings.h>
#endif
#else
#include <string.h>
#endif
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "cawflib.h"
/*
* Local definitions
*/
#define BOLD 'B'
#define CONFIG "fontfilt.cf"
#define ESC 0x1b
#define ITALIC 'I'
#define MAXLINE 512
#define ROMAN 'R'
/*
* Local global variables
*/
static char *Besc = NULL; /* bold font escape string pointer */
static char *Conf = NULL; /* configuration file path */
static char *Defdev = NULL; /* default device name (last name of
* fontfilt.cf */
static char Font = ROMAN; /* current font */
static char *Iesc = NULL; /* italic font escape string pointer */
static char *Pname; /* program name */
static char *Resc = NULL; /* roman font escape string pointer */
/*
* Structure for font definitions
*/
struct font {
char *nm; /* font name */
char *fi; /* font initialization character sequence */
struct font *next; /* next font fot this device */
};
/*
* Device structure
*/
struct dev {
char *nm; /* device name */
struct font *f; /* supported fonts */
char *b; /* bold font ESCape sequence */
char *i; /* italic font ESCape sequence */
char *r; /* Roman font ESCape sequence */
struct dev *next; /* next device */
} *Dp = NULL;
/*
* Externals
*/
extern char *optarg; /* getopt(3) argument pointer */
extern int optind; /* getopt(3) index */
/*
* Function definitions
*/
static char *Convstr();
static int Convfont(), Readcf();
static void Bold(), Getec(), Italic(), Roman();
#ifndef STDLIB
char *getenv(), *malloc(), *strchr(), *strrchr();
#endif
/*
* Main program
*/
main(argc, argv)
int argc; /* argument count */
char *argv[]; /* argument pointers */
{
register int c; /* character buffer */
char *cnm = NULL; /* config file name */
char *dnm = NULL; /* device name */
struct dev *dp; /* device */
char *fnm = NULL; /* font name */
int err = 0; /* argument error count */
int fc, fx; /* file count and index */
struct font *fp; /* font pointer */
FILE *fs; /* file stream */
int help = 0; /* -h status */
struct stat sbuf; /* file stat() buffer */
char *sep; /* separator pointer */
/*
* Save program name.
*/
if ((Pname = strrchr(argv[0], '\\')) != NULL)
Pname++;
else if ((Pname = strrchr(argv[0], '/')) != NULL)
Pname++;
else
Pname = argv[0];
/*
* Process options.
*/
while ((c = getopt(argc, argv, "c:d:f:h")) != EOF) {
switch (c) {
/*
* -c config -- specify configuration file
*/
case 'c':
if (cnm != NULL) {
(void) fprintf(stderr,
"%s: duplicate config name\n", Pname);
err = 1;
} else
cnm = optarg;
break;
/*
* -d device -- specify device
*/
case 'd':
if (dnm != NULL) {
(void) fprintf(stderr,
"%s: duplicate device name\n", Pname);
err = 1;
} else
dnm = optarg;
break;
/*
* -f font -- specify font
*/
case 'f':
if (fnm != NULL) {
(void) fprintf(stderr,
"%s: duplicate font name\n", Pname);
err = 1;
} else
fnm = optarg;
break;
/*
* -h -- request help
*/
case 'h':
help++;
break;
/*
* unknown option
*/
case '?':
err = 1;
}
}
/*
* Handle file arguments.
*/
if (optind >= argc)
fc = 0;
else {
fc = argc;
for (fx = optind; fx < fc; fx++) {
if (stat(argv[fx], &sbuf) != 0) {
(void) fprintf(stderr, "%s: can't find %s\n",
Pname, argv[fx]);
err++;
}
}
}
/*
* Read configuration file.
*/
if (Readcf(cnm) == 0)
err++;
/*
* Validate device name.
*/
if (dnm == NULL)
dnm = Defdev;
for (dp = Dp; dp; dp = dp->next) {
if (strcmp(dnm, dp->nm) == 0)
break;
}
if (dp) {
if (fnm == NULL && dp->f)
fnm = (dp->f)->nm